<template>
	<m-layout gap="0 0 0" :goBack="false" ftcolor="#fff" title="新闻">
		<m-block class="shop" spa="0 0 23" :isLoading='isPending' bgColor="unset" radius="0">
			<!-- banner -->
			<m-swiper class="" height="280rpx" :bnannerList="bnannerList" radius="0" />
			<!-- fun 金刚区 -->
			<m-block class="newsFun" radius="0">
				<view class="p-24 flex-column ai-center" v-for="(item ,index) in funList" :key="index" @click="Jump(`/pages/news/newsList/newsList?title=${item.title}&code=${item.code}`)">
					<m-icon  :type="item.icon" :size="[114,114]" />
					<text class="fs26">{{item.title}}</text>
				</view>
			</m-block>
			<!-- 列表 -->
			<view class="">
				<template v-for="item in listArr">
					<m-list :itemObj="item" />
				</template>
				<m-loading class="more pb-60" gap="100 0" :list='listArr' :pageIndex="pageIndex" :pageCount="pageCount"
					:loading="isLoading" />
			</view>
		</m-block>
	</m-layout>
</template>
<script>
	import { GetNewsPage } from "@/api/News.js"
	export default {
		data() {
			return {
				funList: [{
						title: '公司要闻',
						icon: 'gsyw',
						code: 'news_gsyw'
					},
					{
						title: '公益事迹',
						icon: 'gysj',
						code: 'news_gysj'
					},
					{
						title: '媒体报道',
						icon: 'mtbd',
						code: 'news_mtbd'
					},
					{
						title: '行业资讯',
						icon: 'hyzx',
						code: 'news_hyzx'
					}
				],
				bnannerList: [],
				isPending: true,
				pageIndex: 1,
				pageSize: 10,
				pageCount: 1,
				listArr: [],
				isLoading: false,
				typeid: '',
				code: '',
			};
		},
		props: {
			// title: {
			// 	type: String,
			// 	default: () => {
			// 		return '列表'
			// 	}
			// }
		},
		onLoad({ title, typeid = '', code = '' }) {
			this.title = title;
			this.typeid = typeid;
			this.code = code;
		},
		mounted() {
			this.init()
		},
		methods: {
			async init() {
				this.pageCount = 1;
				this.pageIndex = 1;
				this.isPending = true;
				await this.sleep(0.5);
				await this.getData();
				await this.getBanner()
				this.isPending = false;
			},
			// 获取banner列表
			async getBanner() {
				const { success, list, msg, code } = await GetNewsPage({
					code: 'banner_xw',
					pageIndex: 1,
					pageSize: 10,
				})
				this.bnannerList = list;
			},
			async getData() {
				if (this.pageIndex > this.pageCount) return;
				this.isLoading = true;
				const { success, totalCount, msg, list, pageCount } = await GetNewsPage({
					code: 'news_gsyw,news_gysj,news_mtbd,news_hyzx',
					pageIndex: this.pageIndex,
					pageSize: this.pageSize,
				});
				this.isLoading = false;
				this.pageCount = pageCount;
				if (this.pageIndex <= 1) {
					this.listArr = list;
				} else {
					this.listArr = [...this.listArr, ...list];
				}
				this.pageIndex++;
				uni.stopPullDownRefresh();
			},
		},
		onPullDownRefresh() {
			this.init();
		},
		onReachBottom() {
			this.getData();
			console.log("触底了");
		},
	}
</script>

<style lang="scss">
	page {
		height: 100%;
	}

	.newsFun {
		display: grid;
		grid-template-columns: repeat(4, 1fr);
		// grid-gap: 20rpx;
		// grid-template-rows: 10rpx 20rpx;
	}
</style>